<template>
    <van-search v-model="searchval" shape="round" background="#4fc08d" placeholder="请输入搜索关键词" />
    <div v-for="item in searchApiData" v-show="kong">
        <router-link :to="{name:'detail',params:{goods_id:item.goods_id}}">
            <van-card :num="item.goods_number" :price="item.goods_price" :title="item.goods_name"
            :thumb="item.goods_small_logo ? item.goods_small_logo : 'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg'" />
        </router-link>
    </div>
    <van-empty description="暂无搜索数据" v-show="kongstatus"/>
</template>

<script setup>
import { searchApi } from '@/api/api';
import _ from 'lodash';
import { ref, watch } from 'vue';
let searchApiData = ref([])
let searchval = ref('')
let kong=ref(false)
let kongstatus=ref(false)
watch(searchval,_.debounce(val=>{
    if(val.length>0){
        kong.value=true
        searchApi(val).then(res=>{
            console.log('搜索数据',res)
            searchApiData.value=res.data.message.goods
            if(res.data.message.length==0){
                kongstatus.value=true
            }else{
                kongstatus.value=false
            }
        })
    }else{
        kong.value=false
    }
},500))
</script>

<style lang="scss" scoped></style>